<?php


namespace app\system\service;

class AuthService
{
	public static function getRoleNoneAuthIds($role_id)
	{
		if ($role_id == 0) {
			return [];
		}
		$role_auth = self::getRoleAuth($role_id);
		$all_auth = self::getAllAuth();
		return array_diff($all_auth, $role_auth);
	}
	public static function getRoleNoneAuthUris($role_id)
	{
		$ids = self::getRoleNoneAuthIds($role_id);
		$result = \think\Db::name("system_admin_menu")->where("id", "in", $ids)->column("uri");
		$data = [];
		foreach ($result as $k => $v) {
			if (empty($v)) {
				continue;
			}
			$data[] = strtolower($v);
		}
		return $data;
	}
	private static function getRoleAuth($role_id)
	{
		return \think\Db::name("system_admin_role_auth")->where(["role_id" => $role_id])->column("menu_auth_id");
	}
	private static function getAllAuth()
	{
		return \think\Db::name("system_admin_menu")->where(["disable" => 0])->column("id");
	}
	public static function getRoleNoneAuthArr($role_id)
	{
		return \think\Db::name("system_admin_menu")->where("id", "in", self::getRoleNoneAuthIds($role_id))->column("uri");
	}
}